﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Constructor
{
    public partial class PaletteItem : UserControl
    {
        public Frame Frame { get; set; }
        public PaletteItem(Frame f)
        {
            InitializeComponent();
            Frame = f;
            lbl_name.Text = f.Name;
            if (f.ContainsImageSlot())
            {
                if (f != null && f.GetImageSlot().Default!=null && External.images.LoadedImages.ContainsKey(f.GetImageSlot().Default.ToString()))
                    img.BackgroundImage = External.images.LoadedImages[f.GetImageSlot().Default.ToString()].BackgroundImage;
            }
            this.MouseDown += new MouseEventHandler(PaletteItem_MouseDown);
        }

        void PaletteItem_MouseDown(object sender, MouseEventArgs e)
        {
            DoDragDrop(Frame, DragDropEffects.Move);
        }

        private void PaletteItem_MouseEnter(object sender, EventArgs e)
        {
            BackColor = Color.FromArgb(255, 239, 187);
            BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
        }

        public void PaletteItem_MouseLeave(object sender, EventArgs e)
        {
            BackColor = Color.White;
            BorderStyle = System.Windows.Forms.BorderStyle.None;
            if (sender != null)
                foreach (PaletteItem item in (this.Parent as FlowLayoutPanel).Controls)
                    if (item != this) item.PaletteItem_MouseLeave(null, null);
        }
    }
}
